package com.lds.config.center.server.client.controller;

import com.lds.config.center.client.common.model.request.GetAllItemRequest;
import com.lds.config.center.client.common.model.request.NotifyUpdateItemRequest;
import com.lds.config.center.client.common.model.response.GetAllItemResponse;
import com.lds.config.center.client.common.model.response.NotifyUpdateItemResponse;
import com.lds.config.center.server.client.service.ClientService;
import com.lds.management.center.common.model.dto.ResultDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;

@RestController
@RequestMapping("/api/client")
@RequiredArgsConstructor
public class ClientController {
    private final ClientService clientService;

    /**
     * 获取所有配置项
     */
    @RequestMapping("/item/get-all")
    public ResultDTO<GetAllItemResponse> getAllItem(@RequestBody GetAllItemRequest request) {
        return clientService.getAllItem(request);
    }

    /**
     * 监听配置项更新
     *
     */
    @RequestMapping("/item/notify-update")
    public DeferredResult<ResultDTO<NotifyUpdateItemResponse>> notifyUpdateItem(@RequestBody NotifyUpdateItemRequest request) {
        return clientService.notifyUpdateItem(request);
    }

}
